package com.baoyouqun.service;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baoyouqun.domain.CreateCmd.DemandCreateCmd;
import com.baoyouqun.domain.Enum.DemandCollectionTypeEnum;
import com.baoyouqun.domain.Enum.DemandInteractTypeEnum;
import com.baoyouqun.domain.Query.AdminDemandQuery;
import com.baoyouqun.domain.Query.DemandQuery;
import com.baoyouqun.domain.Query.DemandUserQuery;
import com.baoyouqun.domain.UpdateCmd.DemandUpdateCmd;
import com.baoyouqun.domain.VO.DemandVO;
import com.baoyouqun.entity.Demand;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

public interface DemandService extends IService

        <Demand> {
    /**
     * 后台管理-已发布帖子：条件分页查询
     *
     * @param query 筛选条件+分页参数（关键词、分类、时间范围等）
     * @return 分页VO列表（含发布人信息、枚举中文描述）
     */
    Page<DemandVO> pageAdminDemand(AdminDemandQuery query);

    /**
     * 后台管理-已发布帖子：POI导出Excel
     *
     * @param query    筛选条件（与分页查询共用，控制导出数据范围）
     * @param response Http响应对象（用于输出Excel流，触发浏览器下载）
     */
    void exportAdminDemandExcel(AdminDemandQuery query, HttpServletResponse response);

    List<Map<String, Object>> countByAreaCodes();

    /**
     * 新增并返回实体
     */
    SingleResponse<DemandVO> create(DemandCreateCmd cmd);

    Response update(DemandUpdateCmd cmd);


    @Transactional(rollbackFor = Exception.class)
    Demand incrementViewCount(Demand demand);

    @Transactional(rollbackFor = Exception.class)
    Response decrementViewCount(String demandId);

    void updateDemandInteractCount(String demandId, DemandInteractTypeEnum type, int num);

    void updateDemandCollectionCount(String demandId, DemandCollectionTypeEnum type, int num);


    /**
     * 根据ID查询VO
     */
    DemandVO selectById(String id);

    /**
     * 分页查询VO
     */
    IPage<DemandVO> pageVo(DemandQuery query);

    IPage<DemandVO> userPageVo(DemandUserQuery query);

    IPage<DemandVO> wxHomePage(DemandQuery query);

    IPage<DemandVO> userCollectionPage(DemandUserQuery query);

    void takeUserVO(List<DemandVO> list);

    Response refreshTop(String demandId);

    Response takeOffShelves(String demandId);

    boolean checkUserPermission(String demandId, String userId);

    void takeUserVO(DemandVO demandVO);

    Response refreshDemand(String demandId);

    Response takeOffDemand(String demandId);

    Response takeOnDemand(String demandId);


    List<Map<String, Object>> countByAreaAndType();

    List<DemandVO> selectByUserId(String userId);

    Map<String, String> selectOwnerMapByTargetIds(List<String> targetIds);
}